const CommentService = require('../service/comment');
class CommentController{
  async createComment(ctx,next){
    //获取参数
    const userId = ctx.user.id;
    const { momentId,content}=ctx.request.body;
    console.log(userId,content,momentId,"id,content");
    //将数据导入数据库
    const result = await CommentService.createComment( momentId,content,userId);
    ctx.response.body = {
        code: 200,
      data: result,
      msg: '评论成功'
    }
  }
  async reply(ctx,next){
    //获取参数
    const commentId = ctx.params.commentId;
    const userId = ctx.user.id;
    const { momentId,content}=ctx.request.body;
    //将数据导入数据库
    const result = await CommentService.reply( commentId,content,userId,momentId);
    ctx.response.body = {
        code: 200,
      data: result,
      msg: '回复成功'
    }
  }
async updateComment(ctx,next){
  //获取参数
  const commentId = ctx.params.commentId;
  const userId = ctx.user.id;
  const { content}=ctx.request.body;
  //将数据导入数据库
  const result = await CommentService.updateComment( commentId,content,userId);
  ctx.response.body = {
      code: 200,
    data: result,
    msg: '修改成功'
  }
}
async deleteComment(ctx,next) {
    const commentId = ctx.params.commentId;
    const userId = ctx.user.id;
    const result = await CommentService.deleteComment(commentId,userId);
    ctx.response.body = {
        code: 200,
      data: result,
      msg: '删除成功'
    }
}
}
module.exports = new CommentController();